home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Workbench / Archive / PP_v1.4 / Source / fnodes.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  2KB  |  71 lines

  1. #include <pragmas.h>
  2. #include <exec/types.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <libraries/dos.h>
  6.  
  7. extern struct MinList templist;
  8.  
  9. /* See 'pp.c' for a more detailed description of this struct */
  10. struct filenode
  11. {
  12.     struct MinNode mn;
  13.  
  14.     BPTR filehandle;            /* Our new file */
  15.     char *new_filename;
  16.     BPTR orig_file;
  17.     short dirty;
  18. };
  19.  
  20. /* Add a file node to the list of files which we have created. These
  21. ** exist temporarily in 'temppath' and we need to get rid of these along
  22. ** the way, as they are Close()'d.
  23. */
  24. addfilenode(register BPTR fn, register char *filename, register BPTR orighndl)
  25. {
  26.     register struct filenode *memgot;
  27.  
  28.     if
  29.     (
  30.         (memgot = AllocMem(sizeof(*memgot),MEMF_CLEAR))         &&
  31.         (memgot->new_filename  = AllocMem(strlen(filename)+1,0))
  32.     )
  33.     {
  34.         memgot->filehandle = fn;
  35.         strcpy(memgot->new_filename,filename);
  36.         memgot->orig_file = orighndl;
  37.         Forbid();
  38.         AddTail((struct List *)&templist, (struct Node *)memgot);
  39.         Permit();
  40.         return(1);
  41.     }
  42.     else
  43.         return(0);
  44. }
  45.  
  46. /* Find a filenode (keyed by its filehandle) */
  47. struct filenode *findfilenode(register BPTR fn)
  48. {
  49.     register struct filenode *search;
  50.  
  51.     /* This function does a Forbid() on entry, so that the list is
  52.     ** not changed while we're searching in it
  53.     */
  54.  
  55.     Forbid();
  56.  
  57.     /* Linear search is employed */
  58.     for
  59.     (
  60.         search = (struct filenode *)(templist.mlh_Head);
  61.         search->mn.mln_Succ;
  62.         search = (struct filenode *)(search->mn.mln_Succ)
  63.     )
  64.         if (search->filehandle == fn)
  65.             break;
  66.  
  67.     Permit();
  68.  
  69.     return(search->mn.mln_Succ? search : NULL);
  70. }
  71.